package com.huopaolan.yohuoshop.Mvp.View.Fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;

import com.huopaolan.yohuoshop.Adapter.ViewPagerAdapter.MyFragmentPagerAdapter;
import com.huopaolan.yohuoshop.Mvp.View.Activity.HomeActivity;
import com.huopaolan.yohuoshop.R;

import java.util.ArrayList;
import java.util.List;

public class StrollFragment extends Fragment {
    private ViewPager stroll;
    private TabLayout stroll_tab;
    private List<Fragment> fragmentList = new ArrayList<>();
    private List<String> stringList = new ArrayList<>();
    private MyFragmentPagerAdapter myFragmentPagerAdapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.fragment_stroll, container, false);
        initView(inflate);
        initData();
        iniAdapter();
        return inflate;
    }

    @Override
    public void onStart() {
        Window window = getActivity().getWindow();
        window.setStatusBarColor(Color.BLACK);
        super.onStart();
    }

    private void iniAdapter() {
        myFragmentPagerAdapter = new MyFragmentPagerAdapter(getChildFragmentManager(), fragmentList, stringList);
        stroll.setAdapter(myFragmentPagerAdapter);
    }

    private void initData() {
        fragmentList.add(new StrollNewFragment());
        fragmentList.add(new StrollNewFragment());
        fragmentList.add(new StrollNewFragment());
        fragmentList.add(new StrollNewFragment());
        fragmentList.add(new StrollNewFragment());
        stringList.add("最新");
        stringList.add("搭配");
        stringList.add("头条");
        stringList.add("上新");
        stringList.add("视频");
        stroll_tab.setupWithViewPager(stroll);
    }

    private void initView(View inflate) {
        stroll = inflate.findViewById(R.id.stroll_viewpager);
        stroll_tab = inflate.findViewById(R.id.stroll_tab);
    }
}
